par = []

def pop() :
	global par 
	tos = par[-1] 
	par[-1:] = [] 
	return tos

def push(v) :
	global par
	par += [v]

def dot_s() :
	global par
	print par

def xm_s() :
	global par
	par = []

def dup() :
	n = pop()
	push( n ) 
	push( n )

def swap() :
	n2 = pop() 
	n1 = pop()
	push( n2 ) 
	push( n1 )

def over() :
	n2 = pop() 
	n1 = pop()
	push( n1 ) 
	push( n2 ) 
	push( n1 )

def drop() :
	n2 = pop() 
	n1 = pop()
	push( n1 )

def nip() :
	n2 = pop() 
	n1 = pop()
	push( n2 )

def rot() :
	n3 = pop() 
	n2 = pop() 
	n1 = pop()
	push( n2 ) 
	push( n3 ) 
	push( n1 )

def depth() :
	n = len(par)
	push( n )

def dot_() :
	text = pop()
	print text,

def cr() :
	print

def dot_cr() :
	text = pop()
	print text

def space() :
	print '',

def spaces() :
	n = pop()
	print (n-1) * ' ',

def sgn() :
	n1 = pop()
	if n1 > 0:
		n2 = 1
	elif n1 < 0:
		n2 = -1
	else:
		n2 = 0
	push( n2 )

def test_sub() : 
	a = pop()
	a += 1
	push( a ) 
	b = pop() 
	push( b ) 



push( 9 )
test_global = pop()

def test_variable() : 
	a = pop() 
	b = 0
	push( a ) 
	b = pop()
	print a,
	print a,
	cr()
	push( a ) 
	dot_s()
	test_sub()
	c = pop() 
	push( c ) 


def indent_test() : 
	push( 1 )
	dup()
	if pop():
		drop()
		push( 2 )
	else:
		drop()
		push( 44 )  


def test_button() : 
	push( 1 )
	dot_s()  


def test_dupswaps() : 
	t = 0
	push( "--test dupswaps"  ) ; print pop(),
	xm_s()
	push( 1 )
	push( 2 )
	push( 3 )
	dot_s()
	push( "! @"  ) ; print pop(),
	cr()
	t = pop()
	dot_s()
	push( t ) 
	dot_s()
	push( "drop swap over"  ) ; print pop(),
	cr()
	drop()
	dot_s()
	swap()
	dot_s()
	over()
	dot_s()
	push( "nip 3 rot depth"  ) ; print pop(),
	cr()
	nip()
	dot_s()
	push( 3 )
	rot()
	dot_s()
	depth()
	dot_s()  


def test_output() : 
	push( "--Testing output"  ) ; print pop(),
	cr()
	push( 1 )
	dot_()
	push( 2 )
	dot_()
	cr()
	push( 1 )
	dot_()
	space()
	push( 2 )
	dot_()
	cr()
	push( 1 )
	dot_()
	push( 2 )
	spaces()
	push( 2 )
	dot_()
	cr()
	push( 1 )
	dot_()
	push( " "  ) ; 
	dot_()
	push( 2 )
	dot_()
	cr()
	push( "Hi"  ) ; 
	dot_()
	push( "Ho"  ) ; 
	dot_()
	push( "Hi"  ) ; print pop(),
	push( "Ho"  ) ; print pop(),
	push( "Hi Ho"  ) ; 
	dot_cr()  


def test_arithmetic() : 
	push( "-- test arithmetic"  ) ; print pop(),
	cr()
	push( 4 )
	push( 2 )
	push(pop()+pop())
	dot_cr()
	push( 5 )
	push(pop()+1)
	dot_cr()
	push( 7 )
	push(pop()-1)
	dot_cr()
	push( 2 )
	push( 3 )
	push(pop()*pop())
	dot_cr()
	push( 12 )
	push( 2 )
	tos = pop(); push(pop() / tos)
	dot_cr()
	push( 20 )
	push( 7 )
	tos = pop(); push(pop()%tos)
	dot_cr()
	push( 6.6 )
	push(int(pop()))
	dot_cr()
	push( 6 )
	push( 7 )
	push(min(pop(),pop()))
	dot_cr()
	push( 6 )
	push( 5 )
	push(max(pop(),pop()))
	dot_cr()
	push( -6 )
	push(abs(pop()))
	dot_cr()
	push( -6 )
	sgn()
	dot_cr()
	push( 6 )
	sgn()
	dot_cr()
	push( 0 )
	sgn()
	dot_cr()  



push( "test global: "  ) ; print pop(),
push( test_global ) 
dot_()
cr()
push( "test variable and sub, should give same stack, top incremented"  ) ; print pop(),
cr()
push( 1 )
test_variable()
dot_s()
test_dupswaps()
test_output()
test_arithmetic()

def broken() : 
	push( 1 )
	drop()  




